package com.zzl.bonds.ticket.controller;

import com.zzl.apidoc.annotation.ApidocController;
import com.zzl.apidoc.annotation.ApidocOperation;
import com.zzl.apidoc.annotation.ApidocParam;
import com.zzl.bonds.ticket.constant.status.TicketStatusEnum;
import com.zzl.bonds.ticket.dto.TicketTransferPage;
import com.zzl.bonds.ticket.dto.TicketransferUpdateDto;
import com.zzl.bonds.ticket.service.TicketTransferService;
import com.zzl.general.common.apidoc.annotation.ApidocParamsPage;
import com.zzl.general.common.apidoc.annotation.ApidocReturnPage;
import com.zzl.general.common.apidoc.annotation.ApidocReturnR;
import com.zzl.general.common.ctrl.WebBaseCtrl;
import com.zzl.general.common.exception.SysException;
import com.zzl.general.common.utils.LogUtils;
import com.zzl.general.common.utils.PageUtils;
import com.zzl.general.common.utils.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * 转让申请单
 *
 * @author sunpp
 * @date 2022-02-16 11:14:07
 */
@ApidocController("平台处理转让")
@RestController
@SuppressWarnings("javadoc")
@RequestMapping("bondsticket/platformTicketransfer")
@Slf4j
public class PlatformTicketransferController extends WebBaseCtrl {
    @SuppressWarnings("all")
    @Autowired
    private TicketTransferService ticketTransferService;


    /**
     * 分页查询转让审核列表凭证列表  平台端
     */
    @GetMapping("/listApprove")
    @ApidocOperation(description = "分页查询转让审核列表凭证列表", operationId = "/ticket/ticketransfer/listSignApprove/1")
    @ApidocReturnPage(genericTypeClass = TicketTransferPage.class)
    public Result listSignApprove(@ApidocParamsPage(name = "params", keyName = {
            "ticketNo"
            , "receiveEnterpriseName",
            "transferEnterpriseName"
            , "openEnterpriseId"
            , "createStartTime"
            , "createEndTime"
            , "startAmount"
            , "endAmount"
            , "handStatus"
            , "page"
            , "order"
    }
            , keyDescription = {
            "凭证编号"
            , "收单企业"
            , "转让方名称"
            , "开票方id"
            , "转让开始日期"
            , "转让结束日期"
            , "开始金额"
            , "结束金额"
            , "处理状态，见接口与原型 依次 123"
            , "排序类型：create_time（默认）、invoice_time：开单日期、cash_time：到期日期，ticket_amount：凭证金额"
            , "排序方式：desc 降序（默认）asc 升序"})
                                  @RequestParam Map<String, Object> params) {
        params.put("ticketStatus", TicketStatusEnum.TRANSFER_PENDING_APPROVE.getCode());
        PageUtils page = ticketTransferService.listPlatformApprove(params, this.getUser());
        return Result.ok().put("page", page);
    }

    /**
     * 转让平台复核
     */
    @PutMapping("/approveTransferOrder")
    @ApidocOperation(description = "转让平台审批申请单", operationId = "9024")
    @ApidocReturnR
    public Result signTransferOrder(@ApidocParam(name = "修改的转让申请单对象值", required = true) @Validated @RequestBody TicketransferUpdateDto ticketransfer) {
        try {
            ticketTransferService.approveTransferOrder(ticketransfer, this.getUser());
            return Result.ok();
        } catch (SysException e) {
            LogUtils.logSysException(log, e);
            return Result.error(e.getMsg());
        }
    }

}
